<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>中文卡片翻转游戏</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="https://unpkg.com/vue@3"></script>
    
    <!-- Tailwind 配置 -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#36CFC9',
                        accent: '#FF7D00',
                        dark: '#1D2129',
                        light: '#F2F3F5'
                    },
                    fontFamily: {
                        sans: ['Inter', 'system-ui', 'sans-serif'],
                    },
                    animation: {
                        'float': 'float 3s ease-in-out infinite',
                        'pulse-slow': 'pulse 4s cubic-bezier(0.4, 0, 0.6, 1) infinite',
                    },
                    keyframes: {
                        float: {
                            '0%, 100%': { transform: 'translateY(0)' },
                            '50%': { transform: 'translateY(-10px)' },
                        }
                    }
                },
            }
        }
    </script>
    
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .card-flip {
                perspective: 1000px;
                transform-style: preserve-3d;
            }
            .card-inner {
                transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
                transform-style: preserve-3d;
            }
            .card-front, .card-back {
                backface-visibility: hidden;
                -webkit-backface-visibility: hidden;
                transition: opacity 0.8s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
            }
            .card-front {
                transform: rotateY(180deg);
            }
            .flipped .card-inner {
                transform: rotateY(180deg);
            }
            .flipped .card-back {
                opacity: 0;
            }
            .flipped .card-front {
                opacity: 1;
            }
            .text-shadow {
                text-shadow: 0 2px 4px rgba(0,0,0,0.1);
            }
            .bg-pattern {
                background-image: radial-gradient(rgba(22, 93, 255, 0.05) 1px, transparent 1px);
                background-size: 20px 20px;
            }
            .touch-feedback {
                transition: transform 0.1s ease-in-out;
            }
            .touch-feedback:active {
                transform: scale(0.95);
            }
            .card-shadow-hover:active {
                box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
            }
            .shine-effect {
                position: relative;
                overflow: hidden;
            }
            .shine-effect::after {
                content: '';
                position: absolute;
                top: -100%;
                left: -100%;
                width: 300%;
                height: 300%;
                background: linear-gradient(
                    135deg, 
                    rgba(255, 255, 255, 0) 0%,
                    rgba(255, 255, 255, 0.8) 50%,
                    rgba(255, 255, 255, 0) 100%
                );
                animation: shine 0.8s ease-out;
                pointer-events: none;
                z-index: 10;
            }
            @keyframes shine {
                0% {
                    transform: translateX(-100%) translateY(-100%) rotate(-45deg);
                }
                100% {
                    transform: translateX(100%) translateY(100%) rotate(-45deg);
                }
            }
            /* 添加额外的发光效果 */
            .glow-effect {
                animation: glow 0.5s ease-out;
            }
            @keyframes glow {
                0% {
                    box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
                }
                50% {
                    box-shadow: 0 0 20px rgba(255, 255, 255, 0.9), 0 0 30px rgba(255, 255, 255, 0.7);
                }
                100% {
                    box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
                }
            }
            /* 多面体相关样式 */
            .perspective-1000 {
                perspective: 1000px;
            }
            .transform-style-3d {
                transform-style: preserve-3d;
            }
            .transition-transform-1000 {
                transition: transform 1s ease-in-out;
            }
            .transition-opacity-300 {
                transition: opacity 0.3s ease;
            }
        }
    </style>
</head>
<body class="bg-blue-50 bg-pattern min-h-screen font-sans text-dark overflow-x-hidden">
    <div id="app">
        <!-- 顶部导航 -->
        <header class="bg-white/90 backdrop-blur-md shadow-sm sticky top-0 z-50 transition-all duration-300" :class="{ 'py-2 shadow': isScrolled, 'py-4': !isScrolled }">
            <div class="container mx-auto px-4 py-4 flex flex-col items-center">
                <div class="flex items-center space-x-2 mb-3">
                    <i class="fa fa-clone text-primary text-2xl"></i>
                    <h1 class="text-xl md:text-2xl font-bold">中文卡片翻转</h1>
                </div>
                
                <!-- 游戏模式标签页 -->
                <div class="flex rounded-full bg-gray-100 p-1 mb-3">
                    <button 
                        class="px-5 py-1.5 rounded-full text-sm font-medium transition-all duration-300"
                        :class="{ 'bg-primary text-white shadow-sm': currentGameMode === 'cards', 'text-gray-700': currentGameMode !== 'cards' }"
                        @click="switchGameMode('cards')"
                    >
                        卡片翻转
                    </button>
                    <button 
                        class="px-5 py-1.5 rounded-full text-sm font-medium transition-all duration-300"
                        :class="{ 'bg-primary text-white shadow-sm': currentGameMode === 'polyhedron', 'text-gray-700': currentGameMode !== 'polyhedron' }"
                        @click="switchGameMode('polyhedron')"
                    >
                        多面体旋转
                    </button>
                </div>
                
                <div class="flex items-center space-x-4 w-full justify-between">
                    <div class="flex items-center space-x-1 text-sm">
                        <i class="fa fa-check-circle text-accent"></i>
                        <span id="flipped-count" class="font-medium">{{ flippedCards }}</span>
                        <span>/</span>
                        <span id="total-count" class="font-medium">{{ totalCards }}</span>
                    </div>
                    <button id="refresh-btn" class="p-3 rounded-full hover:bg-gray-100 transition-colors touch-feedback" @click="newGame" @touchstart="newGame">
                        <i class="fa fa-refresh text-primary text-lg"></i>
                    </button>
                </div>
            </div>
        </header>
        
        <!-- 根据当前游戏模式显示对应内容 -->
        <div v-if="currentGameMode === 'cards'">
            <!-- 原有的卡片游戏内容 -->
            <main class="container mx-auto px-4 py-8 md:py-16">
                <!-- 游戏信息 -->
                <div class="text-center mb-8 md:mb-12">
                    <h2 class="text-[clamp(1.5rem,3vw,2.5rem)] font-bold mb-3 text-dark">卡片翻转挑战</h2>
                    <p class="text-gray-600 max-w-2xl mx-auto">点击卡片翻转查看中文内容，挑战你的记忆力！</p>
                </div>

                <!-- 卡片容器 -->
                <div id="card-container" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-4 md:gap-6 mb-10">
                    <div v-for="(card, index) in cards" :key="card.id" 
                         class="card-flip w-full aspect-square cursor-pointer animate-float touch-feedback card-shadow-hover" 
                         :class="{ 'flipped': card.flipped, 'shine-effect': card.isShining, 'glow-effect': card.isGlowing }" 
                         :style="{ animationDelay: `${index * 0.1}s` }" 
                         @click="flipCard(card)" 
                         @touchstart="flipCard(card)">
                        <div class="card-inner relative w-full h-full rounded-xl shadow-lg">
                            <!-- 卡片背面 -->
                            <div class="card-back absolute inset-0 bg-gradient-to-br flex flex-col items-center justify-center p-4 text-white" :class="card.color">
                                <i class="fa fa-question-circle text-4xl mb-2"></i>
                                <span class="text-sm font-medium">点击翻转</span>
                                <div class="absolute inset-0 bg-white/10 rounded-xl"></div>
                            </div>
                            
                            <!-- 卡片正面 -->
                            <div class="card-front absolute inset-0 bg-gradient-to-br from-white to-gray-100 flex items-center justify-center p-6 rounded-xl">
                                <div class="text-center">
                                    <h3 class="text-2xl md:text-3xl font-bold text-dark">{{ card.text }}</h3>
                                </div>
                                <div class="absolute top-3 right-3 text-primary/70">
                                    <i class="fa fa-check-circle"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 控制按钮 -->
                <div class="text-center mt-8">
                    <button id="new-game-btn" 
                            class="bg-primary hover:bg-primary/90 text-white font-medium py-4 px-10 rounded-full shadow-lg hover:shadow-xl transform transition-all duration-300 flex items-center justify-center mx-auto touch-feedback" 
                            :class="{ 'scale-95': isButtonPressed }" 
                            @click="newGame" 
                            @touchstart="newGame">
                        <i class="fa fa-random mr-2"></i>
                        <span>新游戏</span>
                    </button>
                </div>

                <!-- 卡片类别选择 -->
                <div class="mt-10 max-w-3xl mx-auto">
                    <h3 class="text-center text-lg font-semibold mb-4">选择卡片类别</h3>
                    <div class="flex flex-wrap justify-center gap-3" id="category-buttons">
                        <button v-for="(category, key) in cardCategories" :key="key" 
                                class="px-5 py-3 rounded-full text-sm font-medium transition-all duration-300 touch-feedback" 
                                :class="{ 'bg-primary text-white shadow-md': currentCategory === key, 'bg-white text-gray-700 hover:bg-gray-100': currentCategory !== key }" 
                                @click="changeCategory(key)" 
                                @touchstart="changeCategory(key)">
                            {{ category.name }}
                        </button>
                    </div>
                </div>
            </main>

            <!-- 页脚 -->
            <footer class="bg-white/90 backdrop-blur-md mt-16 py-6">
                <div class="container mx-auto px-4 text-center text-gray-500 text-sm">
                    <p>© 2025 中文卡片翻转游戏 | 点击卡片查看内容</p>
                </div>
            </footer>
        </div>
        
        <!-- 多面体游戏内容 -->
        <div v-else-if="currentGameMode === 'polyhedron'" class="container mx-auto px-4 py-8 md:py-16">
            <div class="text-center mb-8 md:mb-12">
                <h2 class="text-[clamp(1.5rem,3vw,2.5rem)] font-bold mb-3 text-dark">多面体旋转挑战</h2>
                <p class="text-gray-600 max-w-2xl mx-auto">点击按钮旋转多面体，学习显示的中文词汇！</p>
            </div>
            
            <!-- 多面体容器 -->
            <div class="flex flex-col items-center justify-center mb-10">
                <div class="perspective-1000 w-64 h-64 md:w-80 md:h-80 relative" ref="polyhedronContainer">
                    <div class="polyhedron relative w-full h-full transform-style-3d transition-transform-1000" :style="{ transform: polyhedronTransform }">
                        <!-- 多面体的各个面 -->
                        <div v-for="(face, index) in polyhedronFaces" :key="index" 
                             class="absolute inset-0 flex items-center justify-center p-6 rounded-lg shadow-lg bg-gradient-to-br text-white text-center transition-opacity-300" 
                             :class="face.color"
                             :style="getFaceStyle(index)">
                            <h3 class="text-2xl md:text-3xl font-bold">{{ face.text }}</h3>
                        </div>
                    </div>
                </div>
                
                <!-- 旋转按钮 -->
                <button id="rotate-polyhedron-btn" 
                        class="mt-10 bg-primary hover:bg-primary/90 text-white font-medium py-4 px-10 rounded-full shadow-lg hover:shadow-xl transform transition-all duration-300 flex items-center justify-center mx-auto touch-feedback"
                        :class="{ 'scale-95': isRotating }"
                        @click="rotatePolyhedron"
                        :disabled="isRotating">
                    <i class="fa fa-refresh mr-2"></i>
                    <span>{{ isRotating ? '旋转中...' : '旋转多面体' }}</span>
                </button>
            </div>
            
            <!-- 显示历史记录 -->
            <div class="max-w-2xl mx-auto mt-12">
                <h3 class="text-center text-lg font-semibold mb-4">最近显示的词汇</h3>
                <div class="flex flex-wrap justify-center gap-2">
                    <span v-for="(item, index) in recentItems" :key="index" 
                          class="px-3 py-1 bg-white rounded-full shadow-sm text-sm">
                        {{ item }}
                    </span>
                </div>
            </div>
        </div>
        
        <!-- 页脚 -->
        <footer class="bg-white/90 backdrop-blur-md mt-16 py-6">
            <div class="container mx-auto px-4 text-center text-gray-500 text-sm">
                <p>© 2025 中文卡片翻转游戏 | 点击卡片查看内容</p>
            </div>
        </footer>
    </div>

    <script>
        const { createApp, ref, reactive, computed, onMounted, onUnmounted } = Vue;
        
        createApp({
            setup() {
                // 中文卡片内容 - 不同类别
                const cardCategories = reactive({
                    animals: {
                        name: "复习",
                        items: ["叔叔","阿姨","游玩","草地","花园","大树","小屋","小河","高兴","爸爸","妈妈","爷爷","奶奶","外公","外婆","宝宝"]
                    },
                    fruits: {
                        name: "水果",
                        items: ["苹果", "香蕉", "橙子", "草莓", "西瓜", "葡萄", "菠萝", "芒果", "猕猴桃", "樱桃", "蓝莓", "柠檬"]
                    },
                    vegetables: {
                        name: "蔬菜",
                        items: ["胡萝卜", "西红柿", "黄瓜", "土豆", "白菜", "茄子", "辣椒", "洋葱", "大蒜", "菠菜", "芹菜", "南瓜"]
                    },
                    colors: {
                        name: "颜色",
                        items: ["红色", "蓝色", "绿色", "黄色", "紫色", "橙色", "黑色", "白色", "灰色", "粉色", "棕色", "青色"]
                    },
                    numbers: {
                        name: "数字",
                        items: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "百", "千"]
                    }
                });
                
                // 随机背景颜色
                const colors = [
                    'from-blue-500 to-indigo-600',
                    'from-green-500 to-teal-600',
                    'from-purple-500 to-pink-600',
                    'from-yellow-500 to-orange-600',
                    'from-red-500 to-rose-600'
                ];
                
                // 游戏状态
                const currentCategory = ref('animals');
                const flippedCards = ref(0);
                const totalCards = ref(0);
                const cards = ref([]);
                const isButtonPressed = ref(false);
                const isScrolled = ref(false);
                
                // 游戏模式
                const currentGameMode = ref('cards'); // 'cards' 或 'polyhedron'
                
                // 多面体游戏状态
                const polyhedronTransform = ref('rotateX(0deg) rotateY(0deg)');
                const isRotating = ref(false);
                const recentItems = ref([]);
                
                // 多面体的面内容
                const polyhedronFaces = reactive([
                    { text: '你好', color: 'from-blue-500 to-indigo-600' },
                    { text: '再见', color: 'from-green-500 to-teal-600' },
                    { text: '谢谢', color: 'from-purple-500 to-pink-600' },
                    { text: '对不起', color: 'from-yellow-500 to-orange-600' },
                    { text: '请', color: 'from-red-500 to-rose-600' },
                    { text: '是的', color: 'from-cyan-500 to-blue-600' },
                    { text: '不是', color: 'from-emerald-500 to-green-600' },
                    { text: '请坐', color: 'from-violet-500 to-purple-600' }
                ]);
                
                // 获取多面体每个面的样式
                const getFaceStyle = (index) => {
                    const size = 200; // 多面体大小
                    const offset = size / 2;
                    
                    // 为8个面定义不同的位置和旋转角度
                    const positions = [
                        { transform: `translateZ(${offset}px)` },
                        { transform: `rotateY(180deg) translateZ(${offset}px)` },
                        { transform: `rotateY(90deg) translateZ(${offset}px)` },
                        { transform: `rotateY(-90deg) translateZ(${offset}px)` },
                        { transform: `rotateX(90deg) translateZ(${offset}px)` },
                        { transform: `rotateX(-90deg) translateZ(${offset}px)` },
                        { transform: `rotateX(45deg) rotateY(45deg) translateZ(${offset * 1.4}px)` },
                        { transform: `rotateX(-45deg) rotateY(-45deg) translateZ(${offset * 1.4}px)` }
                    ];
                    
                    return positions[index] || positions[0];
                };
                
                // 旋转多面体
                const rotatePolyhedron = () => {
                    if (isRotating.value) return;
                    
                    isRotating.value = true;
                    
                    // 随机选择一个面
                    const randomFaceIndex = Math.floor(Math.random() * polyhedronFaces.length);
                    const selectedFace = polyhedronFaces[randomFaceIndex];
                    
                    // 添加到最近显示的项目
                    recentItems.value.unshift(selectedFace.text);
                    if (recentItems.value.length > 10) {
                        recentItems.value.pop();
                    }
                    
                    // 计算旋转角度，使得选中的面朝向用户
                    let targetRotationX = 0;
                    let targetRotationY = 0;
                    
                    // 根据选中的面设置不同的旋转角度
                    switch (randomFaceIndex) {
                        case 0: targetRotationX = 0; targetRotationY = 0; break;
                        case 1: targetRotationX = 0; targetRotationY = 180; break;
                        case 2: targetRotationX = 0; targetRotationY = -90; break;
                        case 3: targetRotationX = 0; targetRotationY = 90; break;
                        case 4: targetRotationX = -90; targetRotationY = 0; break;
                        case 5: targetRotationX = 90; targetRotationY = 0; break;
                        case 6: targetRotationX = -45; targetRotationY = -45; break;
                        case 7: targetRotationX = 45; targetRotationY = 45; break;
                    }
                    
                    // 添加一些随机旋转使动画更有趣
                    const randomSpinX = Math.floor(Math.random() * 360);
                    const randomSpinY = Math.floor(Math.random() * 360);
                    
                    // 先快速旋转多圈，然后停在目标位置
                    setTimeout(() => {
                        polyhedronTransform.value = `rotateX(${randomSpinX}deg) rotateY(${randomSpinY}deg)`;
                        
                        setTimeout(() => {
                            polyhedronTransform.value = `rotateX(${targetRotationX}deg) rotateY(${targetRotationY}deg)`;
                            
                            setTimeout(() => {
                                isRotating.value = false;
                            }, 1000);
                        }, 500);
                    }, 100);
                };
                
                // 切换游戏模式
                const switchGameMode = (mode) => {
                    currentGameMode.value = mode;
                    if (mode === 'cards') {
                        generateCards(currentCategory.value);
                    }
                };
                
                // 生成随机ID
                const generateId = () => Math.random().toString(36).substr(2, 9);
                
                // 随机选择背景颜色
                const getRandomColor = () => colors[Math.floor(Math.random() * colors.length)];
                
                // 翻转卡片
                const flipCard = (card) => {
                    if (card.flipped) return;
                    
                    // 触发主要闪光特效
                    card.isShining = true;
                    
                    // 触发额外的发光效果
                    card.isGlowing = true;
                    
                    // 翻转卡片
                    card.flipped = true;
                    flippedCards.value++;
                    
                    // 在动画完成后移除特效
                    setTimeout(() => {
                        card.isShining = false;
                    }, 800);
                    
                    setTimeout(() => {
                        card.isGlowing = false;
                    }, 500);
                };
                
                // 生成卡片
                const generateCards = (category = 'animals') => {
                    // 清空卡片数组
                    cards.value = [];
                    
                    // 获取当前类别的卡片内容
                    const categoryData = cardCategories[category];
                    if (!categoryData) return;
                    
                    // 随机选择适当数量的项目（根据屏幕大小）
                    const screenWidth = window.innerWidth;
                    let cardCount = 6; // 更小的默认值，适合小屏幕
                    if (screenWidth >= 360) cardCount = 8;
                    if (screenWidth >= 640) cardCount = 12;
                    if (screenWidth >= 768) cardCount = 12;
                    if (screenWidth >= 1024) cardCount = 12;
                    
                    // 随机排序并选择卡片
                    const shuffledItems = [...categoryData.items].sort(() => Math.random() - 0.5);
                    const selectedItems = shuffledItems.slice(0, cardCount);
                    
                    // 更新游戏状态
                    totalCards.value = selectedItems.length;
                    flippedCards.value = 0;
                    
                    // 创建卡片对象
                    cards.value = selectedItems.map(item => ({
                        id: generateId(),
                        text: item,
                        flipped: false,
                        isShining: false,
                        isGlowing: false,
                        color: getRandomColor()
                    }));
                };
                
                // 新游戏 - 适应两种游戏模式
                const newGame = () => {
                    if (currentGameMode.value === 'cards') {
                        generateCards(currentCategory.value);
                    } else {
                        rotatePolyhedron();
                    }
                    
                    // 按钮动画
                    isButtonPressed.value = true;
                    setTimeout(() => {
                        isButtonPressed.value = false;
                    }, 200);
                };
                
                // 切换类别
                const changeCategory = (category) => {
                    currentCategory.value = category;
                    generateCards(category);
                };
                
                // 窗口滚动事件处理
                const handleScroll = () => {
                    isScrolled.value = window.scrollY > 10;
                };
                
                // 窗口大小改变事件处理
                const handleResize = () => {
                    generateCards(currentCategory.value);
                };
                
                // 生命周期钩子
                onMounted(() => {
                    generateCards(currentCategory.value);
                    window.addEventListener('scroll', handleScroll);
                    window.addEventListener('resize', handleResize);
                });
                
                onUnmounted(() => {
                    window.removeEventListener('scroll', handleScroll);
                    window.removeEventListener('resize', handleResize);
                });
                
                return {
                    cardCategories,
                    currentCategory,
                    flippedCards,
                    totalCards,
                    cards,
                    isButtonPressed,
                    isScrolled,
                    flipCard,
                    newGame,
                    changeCategory,
                    currentGameMode,
                    polyhedronTransform,
                    isRotating,
                    recentItems,
                    polyhedronFaces,
                    getFaceStyle,
                    rotatePolyhedron,
                    switchGameMode
                };
            }
        }).mount('#app');
    </script>
</body>
</html>
